home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / ms-0_06.lha / xms-0.06 / menu.c < prev    next >
C/C++ Source or Header  |  1991-10-29  |  6KB  |  218 lines

  1. /* menu.c - popup menu using the X11R4 SimpleMenu widget */
  2.  
  3. /* (This needs Xaw and it won't work with X11R3) */
  4.    
  5. /*  This file is part of MandelSpawn, a parallel Mandelbrot program for
  6.     the X window system.
  7.  
  8.     Copyright (C) 1990, 1991 Andreas Gustafsson
  9.  
  10.     MandelSpawn is free software; you can redistribute it and/or modify
  11.     it under the terms of the GNU General Public License, version 1,
  12.     as published by the Free Software Foundation.
  13.  
  14.     MandelSpawn is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License,
  20.     version 1, along with this program; if not, write to the Free 
  21.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23.  
  24. #include <stdio.h>
  25.  
  26. #include <X11/IntrinsicP.h>
  27. #include <X11/Xos.h>
  28. #include <X11/StringDefs.h>
  29.  
  30. #include <X11/Xaw/MenuButton.h>
  31. #include <X11/Xaw/SimpleMenu.h>
  32. #include <X11/Xaw/Sme.h>
  33. #include <X11/Xaw/SmeBSB.h>
  34.  
  35. #include <X11/Xaw/Cardinals.h>
  36.  
  37. #include "MsP.h"    /* this is really part of the Ms widget */
  38. #include "Mama.h"
  39.  
  40. extern Screen *myScreen;
  41.  
  42. /* menu choise callbacks */
  43. void
  44.   ZoomPopChoise(), ZoomNopopChoise(), ZoomOutPopChoise(),
  45.   ZoomOutNopopChoise(), 
  46.   JuliaNopopChoise(), JuliaPopChoise(), WindowStatsChoise(),
  47.   SlaveStatisticsChoise(), CloseChoise(), 
  48.   QuitChoise();
  49.  
  50. char msDefaultTranslations[] = 
  51.     "<Btn1Down>:    BeginBox()        \n\
  52.      <Btn1Motion>:    StretchBox()        \n\
  53.      <Btn1Up>:        EndBox()        \n\
  54.      Shift<Btn2Down>:    Zoom(nopop,nojulia,in)    \n\
  55.      <Btn2Down>:    Zoom(popup,nojulia,in)    \n\
  56.      <Btn3Down>:    XawPositionSimpleMenu(menu) MenuPopup(menu) \n\
  57.      Shift<Key>z:    Zoom(nopop,nojulia,in)    \n\
  58.      <Key>z:        Zoom(popup,nojulia,in)    \n\
  59.      Shift<Key>o:    Zoom(nopop,nojulia,out)    \n\
  60.      <Key>o:        Zoom(popup,nojulia,out)    \n\
  61.      Shift<Key>j:    Zoom(nopop,julia,in)    \n\
  62.      <Key>j:        Zoom(popup,julia,in)    \n\
  63.      <Key>s:        ApplStats()        \n\
  64.      <Key>w:        WindowStats()        \n\
  65.      <Key>c:        Close()            \n\
  66.      <Key>q:        Quit()            \n\
  67.   ";
  68.  
  69.  
  70. void MsCreateMenu(w, julia_enabled)
  71.      MsWidget w;
  72.      int julia_enabled;
  73. { Arg arglist[10];
  74.   int num_args=0;
  75.  
  76.   XtSetArg(arglist[num_args], XtNlabel, "MandelSpawn menu");
  77.   num_args++;
  78. #if 0  
  79.   XtSetArg(arglist[num_args], XtNcolormap, DefaultColormapOfScreen(myScreen));
  80.   num_args++;
  81. #endif
  82.   
  83.   w->ms.menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, w, 
  84.     arglist, num_args);
  85.  
  86.   XtAddCallback(
  87.     XtCreateManagedWidget("Zoom",
  88.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  89.     XtNcallback, ZoomPopChoise, (caddr_t)w);
  90.  
  91. #ifndef POPUP_ONLY
  92.   XtAddCallback(
  93.     XtCreateManagedWidget("Zoom (old window)", 
  94.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  95.     XtNcallback, ZoomNopopChoise, (caddr_t)w);
  96. #endif
  97.  
  98.   XtAddCallback(
  99.     XtCreateManagedWidget("Inverse zoom",
  100.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  101.     XtNcallback, ZoomOutPopChoise, (caddr_t)w);
  102.  
  103. #ifndef POPUP_ONLY
  104.   XtAddCallback(
  105.     XtCreateManagedWidget("Inverse zoom (old window)", 
  106.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  107.     XtNcallback, ZoomOutNopopChoise, (caddr_t)w);
  108. #endif
  109.   
  110.   if(julia_enabled)
  111.   {
  112.     XtAddCallback(
  113.       XtCreateManagedWidget("Julia set",
  114.         smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  115.       XtNcallback, JuliaPopChoise, (caddr_t)w);
  116. #ifndef POPUP_ONLY
  117.     XtAddCallback(
  118.       XtCreateManagedWidget("Julia set (old window)", 
  119.     smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  120.       XtNcallback, JuliaNopopChoise, (caddr_t)w);
  121. #endif
  122.   }
  123.   XtAddCallback(
  124.     XtCreateManagedWidget("Performance statistics", 
  125.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  126.     XtNcallback, SlaveStatisticsChoise, (caddr_t)w);
  127.   XtAddCallback(
  128.     XtCreateManagedWidget("Show view coordinates", 
  129.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  130.     XtNcallback, WindowStatsChoise, (caddr_t)w);
  131.   XtAddCallback(
  132.     XtCreateManagedWidget("Close this window", 
  133.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  134.     XtNcallback, CloseChoise, (caddr_t)w);
  135.   XtAddCallback(
  136.     XtCreateManagedWidget("Quit MandelSpawn", 
  137.       smeBSBObjectClass, w->ms.menu, NULL, ZERO),
  138.     XtNcallback, QuitChoise, (caddr_t)w);
  139. }
  140.  
  141. void ZoomNopopChoise(wx, client_data)
  142.      Widget wx;
  143.      caddr_t client_data;
  144. { MsWidget w=(MsWidget)client_data;
  145.   ZoomIn(w, 0, 0, 0);
  146. }
  147.  
  148. void ZoomPopChoise(wx, client_data)
  149.      Widget wx;
  150.      caddr_t client_data;
  151. { MsWidget w=(MsWidget)client_data;
  152.   ZoomIn(w, 1, 0, 0);
  153. }
  154.  
  155. void ZoomOutNopopChoise(wx, client_data)
  156.      Widget wx;
  157.      caddr_t client_data;
  158. { MsWidget w=(MsWidget)client_data;
  159.   ZoomIn(w, 0, 0, 1);
  160. }
  161.  
  162. void ZoomOutPopChoise(wx, client_data)
  163.      Widget wx;
  164.      caddr_t client_data;
  165. { MsWidget w=(MsWidget)client_data;
  166.   ZoomIn(w, 1, 0, 1);
  167. }
  168.  
  169. void JuliaNopopChoise(wx, client_data)
  170.      Widget wx;
  171.      caddr_t client_data;
  172. { MsWidget w=(MsWidget)client_data;
  173.   ZoomIn(w, 0, 1, 0);
  174. }
  175.  
  176. void JuliaPopChoise(wx, client_data)
  177.      Widget wx;
  178.      caddr_t client_data;
  179. { MsWidget w=(MsWidget)client_data;
  180.   ZoomIn(w, 1, 1, 0);
  181. }
  182.  
  183.  
  184. void 
  185. WindowStatsChoise(wx, client_data)
  186.      Widget wx;
  187.      caddr_t client_data;
  188. { MsWidget w=(MsWidget)client_data;
  189.   WindowStats(w);
  190. }
  191.  
  192. void 
  193. SlaveStatisticsChoise(wx, client_data)
  194.      Widget wx;
  195.      caddr_t client_data;
  196. { MsWidget w=(MsWidget)client_data;
  197.   SlaveStatistics(w->ms.mama);
  198. }
  199.  
  200.  
  201. /* Destroy this window (only) */
  202. void 
  203. CloseChoise(wx, client_data)
  204.      Widget wx;
  205.      caddr_t client_data;
  206. { MsWidget w=(MsWidget)client_data;
  207.   XtDestroyWidget(XtParent(w)); /* destroy the shell widget */
  208. }
  209.  
  210.  
  211. /* Ask Mama to shut down */
  212. void 
  213. QuitChoise(w, client_data)
  214.      Widget w;
  215.      caddr_t client_data;
  216. { Shutdown(((MsWidget)client_data)->ms.mama);
  217. }
  218.